<template>
  <div class="member-center">
    <!-- 顶部Banner -->
    <div class="member-banner gradient-animation">
      <div class="banner-content">
        <h1 class="banner-title">温柔升级，给情绪更多陪伴</h1>
        <p class="banner-subtitle">尊享情绪深度关怀，让每一次记录都有温度</p>
      </div>
      <button class="member-btn" @click="selectPlan('monthly')">立即开通</button>
    </div>

    <!-- 权益展示区 -->
    <div class="benefits-section">
      <h2 class="section-title">会员专享权益</h2>
      <div class="benefits-grid">
        <!-- 情绪分析深度升级 -->
        <div class="member-benefit-card">
          <div class="benefit-icon">🧠</div>
          <h3 class="benefit-title">情绪分析深度升级</h3>
          <p class="benefit-desc">情绪根源分析与个性化调节方案，AI智能解读您的情绪</p>
        </div>
        
        <!-- 倾诉区特权 -->
        <div class="member-benefit-card">
          <div class="benefit-icon">💬</div>
          <h3 class="benefit-title">倾诉区特权</h3>
          <p class="benefit-desc">评论优先展示、治愈语音回应、自定义匿名头像</p>
        </div>
        
        <!-- 日记高级功能 -->
        <div class="member-benefit-card">
          <div class="benefit-icon">🔐</div>
          <h3 class="benefit-title">日记高级功能</h3>
          <p class="benefit-desc">无限量加密日记、PDF导出、多设备同步</p>
        </div>
        
        <!-- 专属资源 -->
        <div class="member-benefit-card">
          <div class="benefit-icon">🎵</div>
          <h3 class="benefit-title">专属资源</h3>
          <p class="benefit-desc">会员专属情绪疏导音频，每月1次AI一对一文字咨询</p>
        </div>
        
        <!-- 无广告体验 -->
        <div class="member-benefit-card">
          <div class="benefit-icon">✨</div>
          <h3 class="benefit-title">无广告体验</h3>
          <p class="benefit-desc">屏蔽所有页面广告，专注于您的情绪记录与成长</p>
        </div>
        
        <!-- 会员专属活动 -->
        <div class="member-benefit-card">
          <div class="benefit-icon">🎁</div>
          <h3 class="benefit-title">会员专属活动</h3>
          <p class="benefit-desc">情绪打卡赢延长时长，参与线上情绪沙龙</p>
        </div>
      </div>
    </div>

    <!-- 价格套餐区 -->
    <div class="pricing-section">
      <h2 class="section-title">选择适合您的会员套餐</h2>
      <div class="pricing-grid">
        <!-- 月度套餐 -->
        <div class="member-plan-card" :class="{ selected: selectedPlan === 'monthly' }" @click="selectPlan('monthly')">
          <div class="pricing-header">
            <h3 class="plan-title">月度会员</h3>
            <div class="member-price">
              ¥28<span class="period">/月</span>
            </div>
          </div>
          <div class="pricing-body">
            <ul class="plan-features">
              <li>全部会员权益</li>
              <li>月度自动续费</li>
            </ul>
          </div>
          <div class="pricing-footer">
            <button class="member-btn" :class="{ active: selectedPlan === 'monthly' }">选择</button>
          </div>
        </div>
        
        <!-- 季度套餐 -->
        <div class="member-plan-card" :class="{ selected: selectedPlan === 'quarterly' }" @click="selectPlan('quarterly')">
          <div class="pricing-header">
            <h3 class="plan-title">季度会员</h3>
            <div class="member-price">
              ¥68<span class="period">/3个月</span>
            </div>
            <div class="member-tag">省¥16</div>
          </div>
          <div class="pricing-body">
            <ul class="plan-features">
              <li>全部会员权益</li>
              <li>季度自动续费</li>
              <li>赠送7天会员</li>
            </ul>
          </div>
          <div class="pricing-footer">
            <button class="select-button" :class="{ active: selectedPlan === 'quarterly' }">选择</button>
          </div>
        </div>
        
        <!-- 年度套餐 -->
        <div class="pricing-card" :class="{ active: selectedPlan === 'yearly' }" @click="selectPlan('yearly')">
          <div class="pricing-header">
            <h3 class="plan-title">年度会员</h3>
            <div class="plan-price">
              <span class="price">¥198</span>
              <span class="period">/年</span>
            </div>
            <div class="save-tag best-value">最划算</div>
          </div>
          <div class="pricing-body">
            <ul class="plan-features">
              <li>全部会员权益</li>
              <li>年度自动续费</li>
              <li>赠送30天会员</li>
              <li>送情绪手账电子版</li>
            </ul>
          </div>
          <div class="pricing-footer">
            <button class="select-button" :class="{ active: selectedPlan === 'yearly' }">选择</button>
          </div>
        </div>
      </div>
    </div>

    <!-- 开通方式 -->
    <div class="payment-section">
      <h3 class="payment-title">选择支付方式</h3>
      <div class="payment-options">
        <label class="payment-option">
          <input type="radio" v-model="paymentMethod" value="wechat">
          <span class="payment-icon">💚</span>
          <span class="payment-name">微信支付</span>
        </label>
        <label class="payment-option">
          <input type="radio" v-model="paymentMethod" value="alipay">
          <span class="payment-icon">💙</span>
          <span class="payment-name">支付宝</span>
        </label>
      </div>
      <div class="auto-renewal">
        <input type="checkbox" id="auto-renew" v-model="autoRenew">
        <label for="auto-renew">自动续费</label>
      </div>
      <p class="payment-note">开通后支持随时取消自动续费</p>
      <button class="payment-button" @click="confirmPayment">确认支付</button>
    </div>

    <!-- 会员福利区 -->
    <div class="welfare-section">
      <div class="welfare-item">
        <div class="welfare-icon">🎉</div>
        <div class="welfare-content">
          <h3>会员专属活动</h3>
          <p>参与情绪打卡，赢取会员时长延长</p>
        </div>
      </div>
      <div class="welfare-item">
        <div class="welfare-icon">📈</div>
        <div class="welfare-content">
          <h3>已帮助10,000+人</h3>
          <p>改善情绪状态，找回内心平静</p>
        </div>
      </div>
      <div class="welfare-item">
        <div class="welfare-icon">🎁</div>
        <div class="welfare-content">
          <h3>生日特权</h3>
          <p>会员生日当月赠送情绪礼盒</p>
        </div>
      </div>
    </div>

    <!-- 支付成功提示 -->
    <transition name="fade">
      <div v-if="showSuccessToast" class="success-toast">
        <div class="toast-content">
          <div class="toast-icon">🌟</div>
          <p>开通成功～ 专属情绪陪伴已就位</p>
        </div>
      </div>
    </transition>

    <!-- 花瓣飘落动画容器 -->
    <div class="petals-container" v-if="showPetals"></div>
  </div>
</template>

<script>
export default {
  name: 'MemberCenterView',
  data() {
    return {
      selectedPlan: 'yearly', // 默认选中年度套餐
      paymentMethod: 'wechat',
      autoRenew: true,
      showSuccessToast: false,
      showPetals: false
    }
  },
  computed: {
    isMember() {
      const user = localStorage.getItem('user')
      if (user) {
        const parsedUser = JSON.parse(user)
        return parsedUser.isMember || false
      }
      return false
    }
  },
  methods: {
    selectPlan(plan) {
      this.selectedPlan = plan
    },
    confirmPayment() {
      // 模拟支付流程
      console.log('确认支付:', {
        plan: this.selectedPlan,
        paymentMethod: this.paymentMethod,
        autoRenew: this.autoRenew
      })
      
      // 模拟支付成功
      setTimeout(() => {
        this.updateMemberStatus()
        this.showSuccess()
      }, 1500)
    },
    updateMemberStatus() {
      // 更新用户会员状态到localStorage
      const user = localStorage.getItem('user')
      if (user) {
        const parsedUser = JSON.parse(user)
        parsedUser.isMember = true
        // 设置会员到期时间（模拟）
        const expiryDate = new Date()
        if (this.selectedPlan === 'monthly') {
          expiryDate.setMonth(expiryDate.getMonth() + 1)
        } else if (this.selectedPlan === 'quarterly') {
          expiryDate.setMonth(expiryDate.getMonth() + 3)
        } else {
          expiryDate.setFullYear(expiryDate.getFullYear() + 1)
        }
        parsedUser.memberExpiryDate = expiryDate.toISOString()
        localStorage.setItem('user', JSON.stringify(parsedUser))
      }
    },
    showSuccess() {
      // 显示成功提示
      this.showSuccessToast = true
      this.showPetals = true
      
      // 生成花瓣动画
      this.createPetals()
      
      // 3秒后隐藏提示
      setTimeout(() => {
        this.showSuccessToast = false
        this.showPetals = false
        // 重新加载页面以更新会员状态
        window.location.reload()
      }, 3000)
    },
    createPetals() {
      // 简单的花瓣动画实现
      const container = document.querySelector('.petals-container')
      if (container) {
        container.innerHTML = ''
        for (let i = 0; i < 20; i++) {
          const petal = document.createElement('div')
          petal.className = 'petal'
          petal.style.left = `${Math.random() * 100}vw`
          petal.style.animationDelay = `${Math.random() * 3}s`
          petal.style.backgroundColor = ['#B39DDB', '#D1B8E0', '#E1D5E7', '#C0A9E0'][Math.floor(Math.random() * 4)]
          container.appendChild(petal)
        }
      }
    }
  },
  mounted() {
    // 检查是否已是会员
    if (this.isMember) {
      console.log('用户已是会员')
    }
  }
}
</script>

<style scoped>
/* 全局样式 */
.member-center {
  min-height: 100vh;
  background-color: #F9F9F9;
  padding-bottom: 40px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  position: relative;
  overflow-x: hidden;
}

/* 会员状态信息 */
.member-status-info {
  margin-top: 16px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.2);
  padding: 8px 16px;
  border-radius: 20px;
  color: white;
  font-size: 14px;
}

.crown-icon {
  margin-right: 8px;
  font-size: 16px;
}

.renewal-hint {
  margin-top: 8px;
  color: #FFF3E0;
  font-size: 14px;
  text-align: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
  100% {
    opacity: 1;
  }
}

/* 加载状态 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.loading-spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #B39DDB;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 提示消息 */
.toast {
  position: fixed;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  color: white;
  z-index: 1002;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.success {
  background-color: #4CAF50;
}

.toast.error {
  background-color: #F44336;
}

/* 按钮禁用状态 */
.member-btn:disabled,
.payment-button:disabled {
  background-color: #CCCCCC;
  cursor: not-allowed;
  opacity: 0.8;
}

/* 动画 */
.toast-enter-active, .toast-leave-active {
  transition: all 0.3s ease;
}

.toast-enter-from, .toast-leave-to {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
}

/* Banner样式 */
.member-banner {
  background: linear-gradient(135deg, #B39DDB 0%, #D1B8E0 100%);
  color: white;
  padding: 30px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 0 0 20px 20px;
  margin-bottom: 30px;
  box-shadow: 0 4px 12px rgba(179, 157, 219, 0.2);
}

.banner-content {
  flex: 1;
}

.banner-title {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 10px 0;
}

.banner-subtitle {
  font-size: 16px;
  opacity: 0.9;
  margin: 0;
}

.banner-button {
  background-color: #5E35B1;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.3s;
}

.banner-button:hover {
  background-color: #4527A0;
  transform: translateY(-2px);
}

/* 通用区域标题 */
.section-title {
  font-size: 24px;
  color: #555555;
  text-align: center;
  margin: 0 0 30px 0;
  font-weight: 600;
}

/* 权益展示区 */
.benefits-section {
  padding: 0 20px;
  margin-bottom: 40px;
}

.benefits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.benefit-card {
  background-color: white;
  border: 1px solid #E1D5E7;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
}

.benefit-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(179, 157, 219, 0.2);
}

.benefit-icon {
  font-size: 40px;
  margin-bottom: 16px;
}

.benefit-title {
  font-size: 18px;
  color: #555555;
  margin: 0 0 10px 0;
  font-weight: 500;
}

.benefit-desc {
  font-size: 14px;
  color: #666666;
  line-height: 1.6;
  margin: 0;
}

/* 价格套餐区 */
.pricing-section {
  padding: 0 20px;
  margin-bottom: 40px;
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  max-width: 1000px;
  margin: 0 auto;
}

.pricing-card {
  background-color: white;
  border: 2px solid #F0F0F0;
  border-radius: 16px;
  padding: 24px;
  transition: all 0.3s;
  position: relative;
  cursor: pointer;
}

.pricing-card.active {
  border-color: #B39DDB;
  background-color: rgba(179, 157, 219, 0.05);
  box-shadow: 0 6px 20px rgba(179, 157, 219, 0.2);
  transform: translateY(-4px);
}

.pricing-header {
  text-align: center;
  margin-bottom: 20px;
  position: relative;
}

.plan-title {
  font-size: 20px;
  color: #555555;
  margin: 0 0 12px 0;
  font-weight: 600;
}

.plan-price {
  display: flex;
  align-items: baseline;
  justify-content: center;
  margin-bottom: 12px;
}

.price {
  font-size: 36px;
  color: #B39DDB;
  font-weight: 700;
}

.period {
  font-size: 16px;
  color: #666666;
  margin-left: 4px;
}

.save-tag {
  background-color: #B39DDB;
  color: white;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 10px;
  display: inline-block;
}

.save-tag.best-value {
  background-color: #FF6B6B;
}

.pricing-body {
  margin-bottom: 24px;
}

.plan-features {
  list-style: none;
  padding: 0;
  margin: 0;
}

.plan-features li {
  font-size: 14px;
  color: #666666;
  margin-bottom: 8px;
  padding-left: 20px;
  position: relative;
}

.plan-features li:before {
  content: '✓';
  color: #B39DDB;
  position: absolute;
  left: 0;
  font-weight: bold;
}

.select-button {
  width: 100%;
  padding: 12px;
  border: 2px solid #E1D5E7;
  background-color: white;
  color: #666666;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.select-button.active {
  background-color: #B39DDB;
  color: white;
  border-color: #B39DDB;
}

/* 开通方式 */
.payment-section {
  max-width: 500px;
  margin: 0 auto 40px;
  padding: 0 20px;
}

.payment-title {
  font-size: 20px;
  color: #555555;
  text-align: center;
  margin: 0 0 20px 0;
  font-weight: 600;
}

.payment-options {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

.payment-option {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.payment-option input[type="radio"] {
  margin-right: 8px;
}

.payment-option input[type="radio"]:checked + .payment-icon + .payment-name {
  color: #B39DDB;
  font-weight: 500;
}

.payment-icon {
  font-size: 20px;
  margin-right: 8px;
}

.payment-name {
  font-size: 16px;
  color: #666666;
}

.auto-renewal {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.auto-renewal input[type="checkbox"] {
  margin-right: 8px;
}

.auto-renewal label {
  font-size: 14px;
  color: #666666;
  cursor: pointer;
}

.payment-note {
  text-align: center;
  font-size: 12px;
  color: #999999;
  margin: 0 0 24px 0;
}

.payment-button {
  width: 100%;
  padding: 14px;
  background-color: #B39DDB;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.3s;
}

.payment-button:hover {
  background-color: #9575CD;
  transform: translateY(-2px);
}

/* 会员福利区 */
.welfare-section {
  background-color: white;
  padding: 30px 20px;
  margin: 0 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.welfare-item {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.welfare-item:last-child {
  margin-bottom: 0;
}

.welfare-icon {
  font-size: 32px;
  margin-right: 20px;
}

.welfare-content h3 {
  font-size: 18px;
  color: #555555;
  margin: 0 0 6px 0;
  font-weight: 500;
}

.welfare-content p {
  font-size: 14px;
  color: #666666;
  margin: 0;
}

/* 支付成功提示 */
.success-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  text-align: center;
  z-index: 1000;
}

.toast-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toast-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.toast-content p {
  font-size: 16px;
  color: #555555;
  margin: 0;
}

/* 花瓣飘落动画 */
.petals-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

.petal {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 10px 0 10px 0;
  opacity: 0.8;
  animation: fall linear forwards;
}

@keyframes fall {
  0% {
    top: -10px;
    transform: translateX(0) rotate(0deg);
  }
  100% {
    top: 100vh;
    transform: translateX(calc(var(--direction, 1) * 100px)) rotate(360deg);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .member-banner {
    flex-direction: column;
    text-align: center;
    padding: 40px 20px;
  }
  
  .banner-button {
    margin-top: 20px;
  }
  
  .benefits-grid {
    grid-template-columns: 1fr;
  }
  
  .pricing-grid {
    grid-template-columns: 1fr;
  }
  
  .payment-options {
    flex-direction: column;
  }
  
  .payment-option {
    justify-content: center;
  }
  
  .welfare-item {
    flex-direction: column;
    text-align: center;
  }
  
  .welfare-icon {
    margin-right: 0;
    margin-bottom: 12px;
  }
}

/* 过渡动画 */
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
</style>